package cn.hxzy.course.mapper;

import cn.hxzy.common.domain.Video;
import cn.hxzy.common.domain.VideoJd;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author niuyi
 * @since 2024-06-22
 */
public interface VideoMapper extends BaseMapper<Video> {


    //视频名称模糊查询
    @Select("SELECT \n" +
            "    v.video_name,\n" +
            "    v.video_id,\n" +
            "    v.video_hours,\n" +
            "    v.video_path\n" +
            "FROM \n" +
            "    sys_course AS c\n" +
            "JOIN \n" +
            "    sys_chapter AS ch ON c.course_id = ch.course_id\n" +
            "JOIN \n" +
            "    sys_section AS s ON ch.chapter_id = s.chapter_id\n" +
            "JOIN \n" +
            "    sys_video AS v ON s.section_id = v.section_id\n" +
            "WHERE \n" +
            "    c.course_id = #{courseId}\n" +
            "    AND v.video_name LIKE '%${videoName}%'\n" +
            "    AND c.deleted = 0\n" +
            "    AND ch.deleted = 0; ")
    List<Video> selectVideo(String videoName,Long courseId);

    //查此课程所有视频
    @Select("SELECT COUNT(0) FROM sys_video WHERE section_id IN(\n" +
            "SELECT section_id FROM sys_section WHERE chapter_id IN(\n" +
            "SELECT chapter_id FROM sys_chapter WHERE course_id=#{courseId}))")
    double selectCount(Long courseId);

    //查此课程学习完的视频个数
    @Select("SELECT COUNT(0) FROM sys_video_jd WHERE video_id IN(\n" +
            "SELECT video_id FROM sys_video WHERE section_id IN(\n" +
            "SELECT section_id FROM sys_section WHERE chapter_id IN(\n" +
            "SELECT chapter_id FROM sys_chapter WHERE course_id=#{courseId}))) AND user_id=#{userId} AND video_jd_bfb=100")
    double selectNum(Long courseId,Long userId);



    @Select("SELECT video_jd_bfb FROM sys_video_jd WHERE user_id=#{userId} AND video_id = #{videoId}")
    String selectVideoJd(long userId,Integer videoId);

    @Select("SELECT video_path FROM sys_video WHERE video_id = #{videoId}")
    String getVideoPath(Integer videoId);
}
